import type { BaseEntity, ID, PageQuery } from '#/api/common';

import { requestClient } from '#/api/request';

const baseUrl = '/ur_biz/sys_menu';

export interface SysMenu extends BaseEntity {
  menuId: ID;
  menuName: string;
  parentId: ID;
  menuSort: number;
  path: string;
  component: string;
  query: string;
  isCache: boolean;
  isVisible: boolean;
  menuType: string;
  status: string;
  perms: string;
  icon: string;
  children: SysMenu[];
}

// 查询菜单列表
export function listMenu(params?: PageQuery) {
  return requestClient.get<SysMenu[]>(`${baseUrl}/list`, { params });
}

// 查询菜单详细
export function getMenu(id: ID) {
  return requestClient.get<SysMenu>(`${baseUrl}/${id}`);
}

// 新增菜单
export function addMenu(data: SysMenu) {
  return requestClient.post(`${baseUrl}/add`, data);
}

// 修改菜单
export function editMenu(data: SysMenu) {
  return requestClient.post(`${baseUrl}/edit`, data);
}

/**
 * 注意这里只允许单删除
 * @param id ID
 * @returns void
 */
export function delMenu(id: ID) {
  return requestClient.post(`${baseUrl}/remove`, id);
}
